package org.fisco.bcos.asset.service.impl;

import org.fisco.bcos.asset.resp.AccountInfo;
import org.fisco.bcos.sdk.model.CryptoType;
import org.springframework.stereotype.Service;
import org.fisco.bcos.sdk.crypto.CryptoSuite;
import org.fisco.bcos.sdk.crypto.keypair.CryptoKeyPair;
import org.fisco.bcos.asset.service.AccountService;

@Service
public class AccountServiceImpl implements AccountService {

    @Override
    public AccountInfo registerAccount() {
        // 创建非国密类型的CryptoSuite
        CryptoSuite cryptoSuite = new CryptoSuite(CryptoType.ECDSA_TYPE);

        // 随机生成非国密公私钥对
        CryptoKeyPair cryptoKeyPair = cryptoSuite.createKeyPair();

        // 获取账户地址
        String accountAddress = cryptoKeyPair.getAddress();

        // 创建账户信息对象
        AccountInfo accountInfo = new AccountInfo();
        accountInfo.setAddress(accountAddress);
        accountInfo.setPrivateKey(cryptoKeyPair.getHexPrivateKey());
        accountInfo.setPublicKey(cryptoKeyPair.getHexPublicKey());

        return accountInfo;
    }
}